package com.ymatou.query.trading.api.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.query.trading.api.parameter.HasBuyerEverCreatedOrderBean;
import com.ymatou.query.trading.api.service.HasBuyerEverCreatedOrderCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.constant.ECode;
/**
*买家曾经是否在指定卖家下过单
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_HasBuyerEverCreatedOrder{
	private static HasBuyerEverCreatedOrderBean hasbuyerevercreatedorderBean;
	private static HasBuyerEverCreatedOrderCall hasbuyerevercreatedorderCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("买家曾经是否在指定卖家下过单");
	}

	@Before
	public void caseUp() {
		hasbuyerevercreatedorderBean=new HasBuyerEverCreatedOrderBean();
		hasbuyerevercreatedorderCall=new HasBuyerEverCreatedOrderCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(hasbuyerevercreatedorderCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_HasBuyerEverCreatedOrder_001() {
		Logger.start(true,"买家曾经是否在指定卖家下过单");
		try {	    
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
		    hasbuyerevercreatedorderBean.setBuyerId(userId);
		    hasbuyerevercreatedorderBean.setSellerId(sellerId);
			hasbuyerevercreatedorderCall.setData(hasbuyerevercreatedorderBean);
			hasbuyerevercreatedorderCall.callService();						
			List<Map>list=(List<Map>) new DefaultWapper().selectOrderByUserAndSeller(sellerId, userId);
			Logger.verifyEquals(hasbuyerevercreatedorderCall.getData().getBoolean("Yes"), list.size()>0?true:false, "验证数据库");			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
    @Category(P3.class)
    @TestCase
    public void Tc_HasBuyerEverCreatedOrder_002() {
        Logger.start(true,"卖家不存在");
        try {       
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"))+1;
            hasbuyerevercreatedorderBean.setBuyerId(userId);
            hasbuyerevercreatedorderBean.setSellerId(sellerId);
            hasbuyerevercreatedorderCall.setData(hasbuyerevercreatedorderBean);
            hasbuyerevercreatedorderCall.callService();                     
            List<Map>list=(List<Map>) new DefaultWapper().selectOrderByUserAndSeller(sellerId, userId);
            Logger.verifyEquals(hasbuyerevercreatedorderCall.getData().getBoolean("Yes"), list.size()>0?true:false, "验证数据库");           
        } catch (Exception e) {
            Logger.fail(e);
        }
    }
	
	   @Test
	    @Category(P3.class)
	    @TestCase
	    public void Tc_HasBuyerEverCreatedOrder_003() {
	        Logger.start(true,"买家不存在");
	        try {       
	            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"))+1;
	            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
	            hasbuyerevercreatedorderBean.setBuyerId(userId);
	            hasbuyerevercreatedorderBean.setSellerId(sellerId);
	            hasbuyerevercreatedorderCall.setData(hasbuyerevercreatedorderBean);
	            hasbuyerevercreatedorderCall.callService();                     
	            List<Map>list=(List<Map>) new DefaultWapper().selectOrderByUserAndSeller(sellerId, userId);
	            Logger.verifyEquals(hasbuyerevercreatedorderCall.getData().getBoolean("Yes"), list.size()>0?true:false, "验证数据库");           
	        } catch (Exception e) {
	            Logger.fail(e);
	        }
	    }
	   @Test
       @Category(P3.class)
       @TestCase
       public void Tc_HasBuyerEverCreatedOrder_004() {
           Logger.start(true,"买家为0");
           try {       
               int userId =Integer.valueOf(EnvSetup.getData("BuyUserId"));
               int sellerId = 0;
               hasbuyerevercreatedorderBean.setBuyerId(userId);
               hasbuyerevercreatedorderBean.setSellerId(sellerId);
               hasbuyerevercreatedorderCall.setData(hasbuyerevercreatedorderBean);
               hasbuyerevercreatedorderCall.callService();         
               Logger.verifyEquals(ECode.ERROR400, hasbuyerevercreatedorderCall.getString("Code"), "验证Code");
               Logger.verifyEquals(ECode.ERROR400_MSG_34, hasbuyerevercreatedorderCall.getString("Msg"), "验证Code");       
           } catch (Exception e) {
               Logger.fail(e);
           }
       }
	   
	   @Test
       @Category(P3.class)
       @TestCase
       public void Tc_HasBuyerEverCreatedOrder_005() {
           Logger.start(true,"卖家为0");
           try {       
               int userId =0;
               int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
               hasbuyerevercreatedorderBean.setBuyerId(userId);
               hasbuyerevercreatedorderBean.setSellerId(sellerId);
               hasbuyerevercreatedorderCall.setData(hasbuyerevercreatedorderBean);
               hasbuyerevercreatedorderCall.callService();         
               Logger.verifyEquals(ECode.ERROR400, hasbuyerevercreatedorderCall.getString("Code"), "验证Code");
               Logger.verifyEquals(ECode.ERROR400_MSG_33, hasbuyerevercreatedorderCall.getString("Msg"), "验证Code");       
           } catch (Exception e) {
               Logger.fail(e);
           }
       }
}